package com.yangrd.airship.generator;

import com.yangrd.airship.generator.support.PageGeneratorWriter;
import com.yangrd.airship.generator.support.PageTemplateResolver;
import com.yangrd.airship.generator.page.PageGeneratorDefine;
import lombok.RequiredArgsConstructor;

import java.io.File;
import java.util.function.Predicate;

/**
 * @author yangrd
 * @date 2021/11/8
 */
@RequiredArgsConstructor
public class PageGeneratorService {

    private final PageTemplateResolver resolver;

    private final PageGeneratorWriter writer;

    public void gen(PageGeneratorDefine define) {
        gen(define, s -> true);
    }


    public void gen(PageGeneratorDefine define, Predicate<File> fileFilter) {
        try {
            resolver
                    .resolver(fileFilter)
                    .gen(define, writer);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
